package personal.hrsw.mybatisplusdemo.mapper;

import org.apache.ibatis.annotations.*;
import personal.hrsw.mybatisplusdemo.domain.Course;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import personal.hrsw.mybatisplusdemo.domain.Teacher;

import java.util.List;

/**
* @author Administrator
* @description 针对表【course】的数据库操作Mapper
* @createDate 2025-04-24 09:27:23
* @Entity personal.hrsw.mybatisplusdemo.domain.Course
*/
@Mapper
public interface CourseMapper extends BaseMapper<Course> {
    @Select("select * from course ")
    @Results({
            @Result(column = "id",property = "id",javaType = Integer.class),
            @Result(column = "teacher_id",property = "teacher",javaType = Teacher.class,
                    one = @One(select = "personal.hrsw.mybatisplusdemo.mapper.TeacherMapper.selectById")),
            @Result(column = "id",property = "scores",javaType = List.class,
                    one = @One(select = "personal.hrsw.mybatisplusdemo.mapper.ScoreMapper.selectByCourseId"))
    })
    List<Course> selectAll();
    @Delete("delete from course where id=#{id}")
    public int deleteById(int id);
    @Insert("insert into course(name,teacher_id) values (#{name},#{teacher_id})")
    int insert(Course course);
    @Select("select * from course where id=#{id}")
    Course selectById(int id);
    @Update("update course set name=#{name},teacher_id=#{teacher_id} where id=#{id}")
    int update(Course course);
    //    @Select("select * from course limit #{fromIndex},#{pageSize}")
//    List<Course> selectByPage(int fromIndex, int pageSize);
    @Select("select * from course limit #{fromIndex},#{pageSize}")
    @Results({
            @Result(column = "id",property = "id",javaType = Integer.class),
            @Result(column = "teacher_id", property = "teacher", javaType = Teacher.class,
                    one = @One(select = "personal.hrsw.mybatisplusdemo.mapper.TeacherMapper.selectById")),
            @Result(column = "id", property = "scores", javaType = List.class,
                    many = @Many(select = "personal.hrsw.mybatisplusdemo.mapper.ScoreMapper.selectByCourseId"))
    })
    List<Course> selectByPage(int fromIndex, int pageSize);

    @Select("select * from course where id=#{id}")
    Course selectByPrimaryKey(int id);
    @Select("select * from course where teacher_id = #{teacherId}")
    List<Course> selectByTeacherId(int teacherId);
}




